﻿Public Class MaterialSettingForm

    Dim Func As Functions = New Functions
    Public MaterialValue As Double

    Dim MaterialName(100) As String
    Dim MaterialStrength(100) As Double

    'OKボタンを押した時の挙動
    Private Sub ButtonOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOK.Click
        Dim Index As Integer = ComboBoxMaterial.SelectedIndex
        Dim Strength As Double = MaterialStrength(Index)
        Dim path As String = "Material.txt"
        Dim Writer As IO.StreamWriter = New IO.StreamWriter(path)

        Writer.Write(CStr(Strength))

        Writer.Close()

        Me.Close()

    End Sub

    '起動時の挙動（MaterialInfo.txtから，保存している素材の情報を表示）
    Private Sub MaterialSettingForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim path As String = "MaterialInfo.txt"
        Dim Reader As IO.StreamReader = New IO.StreamReader(path)
        Dim Read As String
        Dim retval(10) As String
        Dim InfoCounter As Integer = 0

        While Not Reader.Peek = -1
            Read = Reader.ReadLine
            retval = Read.Split(CChar("/"))
            MaterialName(InfoCounter) = retval(0)
            MaterialStrength(InfoCounter) = CDbl(retval(1))
            InfoCounter += 1
        End While

        ComboBoxMaterial.Items.Clear()

        For i As Integer = 0 To InfoCounter - 1
            ComboBoxMaterial.Items.Add(MaterialName(i))
        Next

        Reader.Close()

    End Sub
End Class